
import React, { Component } from 'react';
import {getList} from "../../../api"
import "./style.scss"
class Index extends Component {
    state={
        list:[]
    }
    async getAndSet(){
        const resp=await getList()
        this.setState({
            list:resp.data.data
        })
    }
    componentDidMount(){
        this.getAndSet()
    }
    toDetail(v){
        this.props.history.push({pathname:'/detail',state:v})
    }
    
    render() {
        const {list}=this.state
        return (
            <div  className='listWrap'>
            {
                list.length&&list.map((v,i)=>{
                    return(
                        <dl key={i} onClick={()=>this.toDetail(v)}>
                            <dt><img src={v.img} alt="" /></dt>
                            <dd>
                                <p>{v.tit}</p>
                                <p>{v.desc}</p>
                                <p style={{color:'red'}}>￥{v.price}</p>
                            </dd>
                        </dl>
                    )
                })
            }
        </div>
        );
    }
}

export default Index;
